package logic

import (
	"context"
	"houses_srv/models"

	"houses_srv/houses"
	"houses_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CommentLookHouseLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCommentLookHouseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommentLookHouseLogic {
	return &CommentLookHouseLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CommentLookHouseLogic) CommentLookHouse(in *houses.CommentLookHouseRequest) (*houses.CommentLookHouseResponse, error) {
	// todo: add your logic here and delete this line

	var h models.LookHouse
	h.UserId = int(in.UserId)
	h.HouseId = int(in.HouseId)
	err := h.ShowOrder()
	if err != nil {
		return nil, err
	}
	
	h.Comment = in.Comment
	h.Status = 2

	err = h.UpdateOrder()
	if err != nil {
		return nil, err
	}

	return &houses.CommentLookHouseResponse{LookHouseId: int64(h.ID)}, nil
}
